//轮播
var banner = {
	size: null,
	time: 3000,
	i: 0,
	timer: null,
	init: function() {
		this.size = $('.banner-box li').size();
		this.autoPlay();
		this.mouse();
	},
	move: function() {
		this.i++;
		if(this.i === this.size) {
			this.i = 0;
		}
		var $li = $('.banner-box li').eq(this.i);
		$li.addClass('in').siblings().removeClass('in');
		this.ctrl();

	},
	autoPlay: function() {
		this.timer = setInterval(this.move.bind(this), this.time);
	},
	ctrl: function() {
		$('.banner-ctrl li').eq(this.i).addClass('in').siblings().removeClass('in');
	},
	clear: function() {
		clearInterval(this.timer);
	},
	mouse: function() {
		$('.banner-ctrl li').click(function(e) {
			this.clear();
			var $target = $(e.target);
			this.i = $target.index();
			var $li = $('.banner-box li').eq(this.i);
			$li.addClass('in').siblings().removeClass('in');
			this.ctrl();
			this.autoPlay();
		}.bind(this))
	},
}
banner.init();
//颜色选择
var chose = {
	size: null,
	i: null,
	img: null,
	zindex: 100,
	init: function() {
		this.size = $('.chose li').size();
		$('.chose li').click(function(e) {
			this.zindex++;
			$li = $(e.target);
			$li.addClass('active').siblings().removeClass('active');
			this.i = $li.index();
			this.img = $('.ys li:eq(' + this.i + ')');
			this.img.animate({
					opacity: 1,
				}, 500)
				.siblings().animate({
					opacity: 0,
				}, 500)

		})
	},

}
chose.init();

//var scroll = {
//	indexT: null,
//	upoffsetT: null,
//	downoffsetT:null,
//	level: null,
//	time: 0,
//	getIndex: function(selector) {
//		this.upoffsetT = $(selector).offset().top;
//		this.downoffsetT = $(selector).offset().top+parseInt($(selector).css('height'));
//		this.level = innerHeight / 2;
//		$(window).scroll(function() {
//			this.indexT = $(window).scrollTop();
//			if(this.upoffsetT < this.level + this.indexT && this.downoffsetT>this.level + this.indexT && this.time === 0) {
//				this.time++;
//				$('.gy-video')[0].play();
//			}
//		}.bind(this))
//	}
//}
//scroll.getIndex('.gy-video');

var scroll = {
	init:function(){
		var $sel=$('.gy-video');
		this.check($sel);
		var $sel2=$('.xh-box');
		this.check($sel2);
	},
	check: function(selector) {
		var time=0;
		var upoffsetT=selector.offset().top;
		var downoffsetT =selector.offset().top+parseInt(selector.css('height'));
		var level = innerHeight / 2;
		var indexT=null;
		$(window).scroll(function() {
			var indexT = $(window).scrollTop();
			if(upoffsetT < level + indexT && downoffsetT>level + indexT && time === 0) {
				time++;
				this.play(selector);
			}
		}.bind(this))
	},
	//工艺视频触发播放
	play(selector){
		if(selector.hasClass('gy-video')){
			selector[0].play();
		}else if(selector.hasClass('xh-box')){
			run.init();
			run2.init();
		}
	}
}
scroll.init();

var run={
	dtc:null,
	time:15,
	timer:null,
	num:0,
	init(){
		this.dtc=$('#distance');
		this.autoPlay();
	},
	witplay:function(){
		this.num++;
		this.dtc.html(this.num);
		if(this.num==120){
			clearInterval(this.timer)
		}
	},
	autoPlay:function(){
		this.timer=setInterval(this.witplay.bind(this),this.time);
	}
	
}
//run.init();
var run2={
	wit:null,
	time:22,
	timer:null,
	num:0,
	init(){
		this.wit=$('#weight');
		this.autoPlay();
	},
	witplay:function(){
		this.num+=0.1;
		this.num=Math.round(this.num*10)/10;
		this.wit.html(this.num);
		if(this.num==8.3){
			clearInterval(this.timer)
		}
	},
	autoPlay:function(){
		this.timer=setInterval(this.witplay.bind(this),this.time);
	}
	
}
//run2.init();
